/**
 * This file is part of codzo-freelance-timetracking.
 * 
 * codzo-freelance-timetracking is free software: you can
 * redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * codzo-freelance-timetracking is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with codzo-freelance-timetracking. If not, see
 * <http://www.gnu.org/licenses/>.
 */


#include <wx/wx.h>
#include "main/timetracker.h"
#include "main/taskbaricon.h"
#include "main/constants.h"

enum {
    PU_RESTORE = 10001,
    PU_HIDE,
    PU_EXIT
};



MainTaskBarIcon::~MainTaskBarIcon()
{
    RemoveIcon();
}

void MainTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&)
{
    wxGetApp().ShowMainWindow(true);
}

void MainTaskBarIcon::OnMenuRestore(wxCommandEvent& )
{
    wxGetApp().ShowMainWindow(true);
}

void MainTaskBarIcon::OnMenuExit(wxCommandEvent& )
{
    wxGetApp().ExitApplication();
}

void MainTaskBarIcon::OnMenuHide(wxCommandEvent& )
{
    wxGetApp().ShowMainWindow(false);
}


// Overridables
wxMenu *MainTaskBarIcon::CreatePopupMenu()
{
    // Try creating menus different ways
    // TODO: Probably try calling SetBitmap with some XPMs here
    wxMenu *menu = new wxMenu;
    menu->Append(PU_RESTORE , _T("&Restore Console"));
    menu->Append(PU_HIDE    , _T("&Hide Console"));    
#ifndef __WXMAC_OSX__ /*Mac has built-in quit menu*/
    menu->AppendSeparator();
    menu->Append(PU_EXIT    , _T("E&xit"));
#endif

    Bind(wxEVT_TASKBAR_LEFT_DCLICK,   &MainTaskBarIcon::OnLeftButtonDClick, this) ;
    Bind(wxEVT_COMMAND_MENU_SELECTED, &MainTaskBarIcon::OnMenuRestore,      this, PU_RESTORE) ;
    Bind(wxEVT_COMMAND_MENU_SELECTED, &MainTaskBarIcon::OnMenuHide,         this, PU_HIDE);
    Bind(wxEVT_COMMAND_MENU_SELECTED, &MainTaskBarIcon::OnMenuExit,         this, PU_EXIT);
    return menu;
}



